package com.cocos.game;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

public class NetworkStateReceiver extends BroadcastReceiver {

    private NetworkCallback callback;
    @Override
    public void onReceive(Context context, Intent intent) {
        JsbHelper.getNetState(context);
    }

    // 注册广播接收器
    public void registerReceiver(Context context) {
        IntentFilter filter = new IntentFilter();
        filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION);
        context.registerReceiver(this, filter);
    }

    // 注销广播接收器
    public void unregisterReceiver(Context context) {
        context.unregisterReceiver(this);
    }

    // 设置回调接口
    public void setCallback(NetworkCallback callback) {
        this.callback = callback;
    }

    // 回调接口
    public interface NetworkCallback {
        void onNetworkConnected();
        void onNetworkDisconnected();
    }
}